import { post } from '@feidao-factory/send-msg/browser/request';
import global from '../../core/global';
import get_sessionid from './_get-sessionid';

/*
 * 设置角色
 * @param actionid 系统参数，fd.data.actionid
 * @param spaceid 系统参数，fd.data.spaceid
 * @param sessionid 系统参数，fd.data.sessionid
 * @param productid 项目productid
 * @param clienttype 端点类型，web：3,h5：2,xcx:9
 * @param role_no 要切换的角色编号
 */
export default async function set_user_role(actionid: string, spaceid: string, productid: string, clienttype: string, role_no: string) {
	try {
		// 获取cookie中的sessionid
		const sessionid = get_sessionid();
		// actionid: string, spaceid: string, sessionid: string, role_no: string

		const url = global.host + 'invoke-atom';
		const obj = {
			msg: [actionid, spaceid, sessionid, productid, clienttype, role_no],
			name: '@feidao-factory/atom/nodejs/authorization/set-user-role'
		};
		const res = await post(url, JSON.stringify(obj));
		return JSON.parse(res.responseText);
	} catch (e) {
		console.error('--请求invoke-atom路由失败--错误信息---', e ? e.toString() : '');
		return Promise.reject(e);
	}
}
